package cn.zhangchg.leetcode.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;

import static org.junit.runner.JUnitCore.main;

public class DInstance {
    private static DInstance instance;

    private DInstance() {

    }
    private static DInstance getInstance() {
        if (instance == null) {
            synchronized (DInstance.class) {
                if (instance == null) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    instance = new DInstance();
                }
            }
        }
        return instance;
    }


    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(DInstance.getInstance().hashCode());
                }
            }).start();
        }
    }
}
